package com.epidata.exam.service;

import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;

import com.epidata.exam.dao.EmployeeDao;
import com.epidata.exam.model.Employee;

// The @Stateless annotation eliminates the need for manual transaction demarcation
@Stateless
public class EmployeeRegistration {

	@Inject
	private Logger log;

	@Inject
	private EmployeeDao<Employee> empleadoDao;

	@Inject
	private Event<Employee> employeeEventSrc;

	public void register(Employee employee) throws Exception {
		log.info("Registering " + employee.getName() + "Con recibos " + employee.getRecibos().size());

		empleadoDao.save(employee);
		employeeEventSrc.fire(employee);
	}
}
